/**
 * 
 */
var vbu09;//会员卡密码
var vbdList = [];//本次计价信息
var vajList = [];//本次费用记录
var totalVbi = 0.0;//本次总消费金额
function checkALlAdvice()
{
	if ($("#checkedAll").prop("checked") == true)
	{
		$("input[name='advice']").each(function()
		{
			$(this).prop("checked", true);
		});
	}
	else
	{
		$("input[name='advice']").each(function()
		{
			$(this).prop("checked", false);
		});
	}
}

// 发送医嘱
function sendAdvice()
{
	var vbd1 = [];
	var vaf1 = [];
	var cbm01Arr = [];
	if ($(".innerHead td input:checked").length <= 0)
	{
		layer.msg("请选择要发送的医嘱",
		{
		time : 2000,
		icon : 0,
		skin: 'layui-layer-msg0'
		});
		return;
	}
	else
	{
		var flag = false;
		$(".innerHead td input:checked").each(function()
				{ // 遍历选中的checkbox
					$(this).parents("tbody").find(".yizhu_details").each(function(i, e)
					{
						var dataStr = $(e).attr("data-info");
						var dataObj = JSON.parse(dataStr);
						var vaf10 = dataObj.vaf10;
						if(vaf10!='1')
						{
							flag=true;
						}
					});
				});
		if(flag)
		{
			layer.alert("医嘱已发送或者已作废，不能再发送！",{icon:0});
			return;
		}
		layer.confirm('是否确定要发送？', 
		{
			btn : [
			'确定', '取消'
			],
			icon:3,
		// 按钮
		}, function()
		{
			layer.msg('发送中....', {icon: 16,skin: 'layui-layer-msg16',shade: [0.1, '#393D49'],time:0});  
			var cbm01Arr_send = [];//生成计价信息用
			$(".innerHead td input:checked").each(function()
			{ // 遍历选中的checkbox
				$(this).parents("tbody").find(".yizhu_details").each(function(i, e)
				{
					var length1 = $(this).parents("tbody").find(".yizhu_details").length;
					var dataStr = $(e).attr("data-info");
					var dataObj = JSON.parse(dataStr);
					vaf1.push(dataObj);

					var vaf01 = dataObj.vaf01;
					var vaf10 = dataObj.vaf10;
					var bda01 = dataObj.bda01;
					var bby01 = dataObj.bby01;
					var bby25 = dataObj.bby25;
					var dsk01 = dataObj.dsk01;
					var bck01b = dataObj.bck01b;
					var cbm01 = dataObj.cbm01;
					cbm01Arr_send.push(cbm01);
					if ("LE".indexOf(bda01)>=0)
					{
						var obj = {};
						obj.cbm01 = cbm01;
						obj.bda01 = bda01;
						cbm01Arr.push(obj);
					}
				});
			});
			cbm01Arr_send = cbm01Arr_send.unique2();//去重
			for(var i = 0;i<cbm01Arr_send.length;i++)
			{
				vbdInfoForsend_final(cbm01Arr_send[i]);
				for (var j = 0; j < vbdList.length; j++)
				{
					var vbdT = {};
					vbdT.vaf01 = vbdList[j]["vaf01"];
					vbdT.bby01 = vbdList[j]["bby01"];
					vbdT.vbd04 = vbdList[j]["vaf21"];// 数量
					vbdT.bby25 = vbdList[j]['bby25'];// 剂量单价
					totalVbi += (vbdT.vbd04*1) * (vbdT.bby25*1);//遍历累加消费金额
					vbdT.vbd05 = vbdList[j]['lprice'];// 门诊包装单价
					vbdT.vbd06 = vbdList[j]['bdu06'];// 是否有从项
					vbdT.bck01 = vbdList[j]['bck01'];// 执行科室
					vbdT.bdn01 = vbdList[j]['bdn01'];// 医嘱项目类型
					vbdT.vbd08 = vbdList[j]['bdu07'];// 费用性质
					vbdT.vbd09 = vbdList[j]['bdu10'];// 收费方式
					vbdT.dsk01 = vbdList[j]['dsk01'];// 药品批次
					vbdT.bby01a = vbdList[j]['bby01a'];// 收费套餐ID
					vbdT.vbd12 = vbdList[j]['vbd12'];// 诊疗收费对照数量
					vbd1.push(vbdT);
				}
			}
			var xml = "{'VAF1':" + JSON.stringify(vaf1) + ",'VBD1':" + JSON.stringify(vbd1) + "}";
			// 预发送
			// $.ajax({
			// url:rootUrl+"/clisendadvice/clinicadvicesendpretreat",
			// data:{"lXml":xml,"lSign":2,"lBCE01":1,"lBCE02":"8080","lBCE03":"管理员","lBCK01":bck01,"lACF01":1,
			// "lVAA07":vac01,"lVAA01":vaa01},
			// dataType:"json",
			// method:"post",
			// success:function(data)
			// {
			// 开始异步发送
			$.ajax(
			{
			url : rootUrl + "/clisendadvice/clinicadvicesend",
			data :
			{
			"lXml" : xml,
			"lSign" : 2,
			"lBCE01" : bce01,
			"lBCE02" : "8080",
			"lBCE03" : bce03,
			"lBCK01" : bck01,
			"lACF01" : 1,
			"lVAA07" : vac01,
			"lVAA01" : vaa01,
			},
			dataType : "json",
			method : "post",
			success : function(data)
			{
				//layer.close(index);
				if (data.result == "Success")
				{
					layer.msg('发送成功',
					{
					time : 2000,
					icon : 1,
					skin: 'layui-layer-msg1'
					});
					// 开始更新医嘱抄送记录和生成诊疗申请单
					var url9 = rootUrl + "/clidoctor/nurse_Lis_Bills_Print";
					var params9 = {};
					params9.bce03 = bce03;
					params9.cbm01Arr = JSON.stringify(cbm01Arr);
					$.ajax(
					{
					async : true,
					url : url9,
					type : 'post',
					dataType : 'json',
					data : params9,
					success : function(data9)
					{
					}
					});
					// 如果是一卡通扣费用户，执行扣费操作
					var vipId = $("#vipId").text();
					if(vipId!="--")
					{
						var msg = "";
						if($("#vbu14").text()*1 < totalVbi)
						{
							msg = "卡内基本余额："+$("#vbu14").text()+"；本次消费总额："+totalVbi+"。请先充值。。。";
							layer.alert(msg, {icon:1,title:"温馨提示："});
							return true;
						}
						else
						{
//							msg = "卡内基本余额："+$("#vbu14").text()+"；本次消费总额："+totalVbi+"。";
//							layer.alert(msg, {icon:1,title:"温馨提示："});
							vbu09 = newCardOut(2);//弹出消费窗口
							vajList = data.rows;
						}
					}
					else
					{
						reloadPatientInfo_jiezhen(vac01);
						patientDoctorAdvice(vac01, 1);
					}
					
				}
				else
				{
					layer.msg('数据异常请联系管理员！',
					{
					time : 2000,
					icon : 2,
					skin: 'layui-layer-msg2'
					});
				}
			},
			error:function(XMLHttpRequest, textStatus, errorThrown)
			{
				alert(errorThrown);
			}
			});
		}, function()
		{

		});
	}

}

/**
 * 点击额确认交易的事件
 */
function chareCardUpdate()
{
	$.ajax({
		url: rootUrl + "/clidoctor/getMD5PassWord",
		type: "GET",
		dataType: 'json',
		data: {password:vbu09},
		success:function(json){
		if(cardMap.vbu09 != json.pass)
		{
			layer.alert("密码错误，请重新输入",{icon:2,title:"提示"});
		}
		else if(cardMap.vbu09 == json.pass)
		{
			layer.closeAll();
			for (var int = 0; int < vajList.length; int++)
			{
				var vaj = vajList[int];
				var params = {};
				params.VAA01 = vaj.vaa01;
				params.VAA07 = vaj.vaa07;
				params.VAI01 = vaj.vai01;
				params.ACF01 = vaj.acf01;
				params.BCE01 = vaj.bce03a;//操作员id
				params.BCK01 = vaj.bck01b;//科室id
				params.BCE02 = vaj.bce02b;//操作员code
				params.BCE02 = vaj.bce03a;//操作员姓名
				params.VAJ38 = vaj.vaj38;//基本账户扣费
				params.AType = 0;//0 = 扣费,1 = 退费
				params.AWorkType = 1;//门诊记账
				var postData = {};
				postData.chargejson = JSON.stringify(params);
				$.ajax
				({
//					url:rootUrl + "/clidoctor/HORate_CardCharge_Update",//直接调用后台
					url:memberUrl+"/member/memberManger/horatecardchargeupdate",//调用rest
//					url:"http://192.168.1.156:8089/rateweb/cloud/member/memberManger/horatecardchargeupdate",
					type:"get",
					dataType:"jsonp",
					async:false,
					data:postData,
					success:function(data)
					{
						var vipId = $("#vipId").text();
						if(data && data.result.toLowerCase()=="success")
						{
							layer.msg("会员卡 "+vipId+" 已成功扣费"+totalVbi+"元",{icon:1,time:2000,skin: 'layui-layer-msg1'});
							printIm(data);
						}
						else 
						{
							layer.alert("会员卡 "+vipId+" 扣费失败，请联系管理员！",{icon:2,title:"警告"});
							printIm(data);
						}
					}
				});
			}
		}
	}});
}


/*//医嘱直接打印
function print(id, cbm01)
{
	var url = printUrl + "/printtoolrest/jpt/" + id + "?cbm01=" + cbm01;
	document.getElementById('appletDiv').innerHTML = "<object classid = 'clsid:CAFEEFAC-0018-0000-0091-ABCDEFFEDCBA'" + "WIDTH = '0' HEIGHT = '0' >" + "<PARAM NAME = 'code' VALUE = 'com.cnhis.cloudhealth.pmsweb.print.JRPrinterApplet.class'>" + "<PARAM NAME = 'codebase'  VALUE = '" + printUrl1 + "'>" + "<PARAM NAME = 'archive'  VALUE = 'reportprint.jar'>" + "<param name = 'type' value = 'application/x-java-applet;version=1.6'>" + "<PARAM NAME = 'scriptable' VALUE='false'>" + "<PARAM NAME = 'REPORT_URL' VALUE='" + url + "'>" + "</object>";
}*/
/**
 * 点击额确认交易的事件--主题二首页
 */
function chareCardUpdate2()
{
	$.ajax({
		url: rootUrl + "/clidoctor/getMD5PassWord",
		type: "GET",
		dataType: 'json',
		data: {password:vbu09},
		success:function(json){
			if(cardMap.vbu09 != json.pass)
			{
				layer.alert("密码错误，请重新输入",{icon:2,title:"提示"});
			}
			else if(cardMap.vbu09 == json.pass)
			{
				layer.closeAll();
				for (var int = 0; int < vajList.length; int++)
				{
					var vaj = vajList[int];
					var params = {};
					params.VAA01 = vaj.vaa01;
					params.VAA07 = vaj.vaa07;
					params.VAI01 = vaj.vai01;
					params.ACF01 = vaj.acf01;
					params.BCE01 = vaj.bce03a;//操作员id
					params.BCK01 = vaj.bck01b;//科室id
					params.BCE02 = vaj.bce02b;//操作员code
					params.BCE02 = vaj.bce03a;//操作员姓名
					params.VAJ38 = vaj.vaj38;//基本账户扣费
					params.AType = 0;//0 = 扣费,1 = 退费
					params.AWorkType = 1;//门诊记账
					var postData = {};
					postData.chargejson = JSON.stringify(params);
					$.ajax
					({
//					url:rootUrl + "/clidoctor/HORate_CardCharge_Update",//直接调用后台
					url:memberUrl+"/member/memberManger/horatecardchargeupdate",//调用rest
//						url:"http://192.168.1.156:8089/rateweb/cloud/member/memberManger/horatecardchargeupdate",
						type:"post",
						dataType:"jsonp",
						async:false,
						data:postData,
						success:function(data)
						{
							var vipId = $("#vipId").text();
							if(data && data.result.toLowerCase()=="success")
							{
								layer.msg("会员卡 "+vipId+" 已成功扣费"+totalVbi+"元",{icon:1,time:2000,skin: 'layui-layer-msg1'});
							}
							else 
							{
								layer.alert("会员卡 "+vipId+" 扣费失败，请联系管理员！",{icon:2,title:"警告"});
							}
							reloadPatientInfo_jiezhen(vac01);
							patientDoctorAdvice(vac01, 1);
						}
					});
				}
			}
		}});
}

/**
 * 病人信息
 */

function reloadPatientInfo_jiezhen(br_vac01)
{
	$.ajax({
		url : rootUrl + "/patientsearch/getpatientinfo",
		data : {
			"productid" : 100,
			"programid" :103010,
			"paramno" : 29,
			"lVAC01" : br_vac01
		},
		type : 'post',
		dataType : 'json',
		success : function(data) {
			if(data){
			    laytplUrl(myurl + "/module/patient_more_info.html",data.list[0], function(data, html) {
			    	 $(".header-content-left").empty().append(html);
			    	 var flag = $(".three-column").find(".main-header").hasClass('br_expanded');
			    	 if(flag){
			    		 $(".patientInfo_more").removeClass("hidden");
			    	 }
				});
			}
		}
	});
}
// function callback(data)
// {
// // vbdList = data.list;
// if (data.result == "Success") {
// layer.msg('发送成功', {
// time : 2000,
// icon : 1
// });
// patientDoctorAdvice($("#vac01").val(), curr);
// } else {
// layer.msg('数据异常请联系管理员！', {
// time : 2000,
// icon : 2
// });
// }
// }

// 发送前的查询--最终版本
function vbdInfoForsend_final(cbm01)
{
	var url = rootUrl + "/advicevaluation/queryForSendParams";
	var data1 = {};
	data1.cbm01 = cbm01;
	$.ajax(
	{
	url : url,
	type : "post",
	data : data1,
	async : false,
	dataType : 'json',
	success : function(data)
	{
		debugger;
		vbdList = [];
		var list = data.list;
		for (var i = 0; i < list.length; i++)
		{
//			if (list[i].vaf01 == vaf01 || list[i].vaf01a == vaf01)
//			{
				vbdList.push(list[i]);
//			}
		}
	}
	});
}

// 查询医嘱计价信息--send用
function vbdInfoForsend(vaf10, vaf01, bda01)
{
	var htmlContent = "";
	var url = "";
	var data1 = {};
	if (vaf10 == 1)
	{
		if (bda01 == "1" || bda01 == "2")// 844
		{
			url = rootUrl + "/advicevaluation/unSendAdviceXiyaoValuation";
			data1.lVAF01A = vaf01;
		}
		else if (bda01 == "3" || bda01 == "8")// 843
		{
			url = rootUrl + "/advicevaluation/unSendAdviceZhongyaoValuation";
			data1.lVAFID = vaf01;
		}
		else if (bda01 == "S")// 1031
		{
			url = rootUrl + "/advicevaluation/unsendadvicevaluation";
			data1.lVAFID = vaf01;
		}
		else
		// 1032
		{
			url = rootUrl + "/advicevaluation/otheradvicecharg";
			data1.lVAFID = vaf01;
		}
	}
	else if (vaf10 == 8)
	{
		if (bda01 == "1" || bda01 == "2")// 1035
		{
			url = rootUrl + "/advicevaluation/sendtempadvicevaluation";
			data1.lVAF01 = vaf01;
			data1.acf01 = "1";
			data1.lVAF01A = "";
		}
		else if (bda01 == "3" || bda01 == "8")// 1036
		{
			url = rootUrl + "/advicevaluation/sendedAdviceCaoyaoValuation";
			data1.lVAFID = vaf01;
		}
		else if (bda01 == "S")// 1037
		{
			url = rootUrl + "/advicevaluation/sendedadvicevaluation";
			data1.lVAFID = vaf01;
		}
		else
		// 1038
		{
			rootUrl + "/advicevaluation/sendotheradvice";
			data1.VAF01 = vaf01;
			data1.acf01 = "1";
		}
	}
	$.ajax(
	{
	url : url,
	type : "post",
	data : data1,
	async : false,
	dataType : 'json',
	success : function(data)
	{
		vbdList = data.list;
	}
	});
}
// 查询医嘱计价信息
function vbdInfo(dataobj)
{
	var vaf10 = dataobj.vaf10;
	var vaf01 = dataobj.vaf01;
	var bda01 = dataobj.bda01;
	var vaf01a = dataobj.vaf01a;
	var htmlContent = "";
	var list;
	var url = "";
	var data1 = {};
	if (vaf10 == 1)
	{
		if (bda01 == "1" || bda01 == "2")// 844
		{
			url = rootUrl + "/advicevaluation/unSendAdviceXiyaoValuation";
			data1.lVAF01A = vaf01a;
		}
		else if (bda01 == "3" || bda01 == "8")// 843
		{
			url = rootUrl + "/advicevaluation/unSendAdviceZhongyaoValuation";
			data1.lVAFID = vaf01;
		}
		else if (bda01 == "S")// 1031
		{
			url = rootUrl + "/advicevaluation/unsendadvicevaluation";
			data1.lVAFID = vaf01;
		}
		else
		// 1032
		{
			url = rootUrl + "/advicevaluation/otheradvicecharg";
			data1.lVAFID = vaf01;
		}
	}
	else if (vaf10 == 8)
	{
		if (bda01 == "1" || bda01 == "2")// 1035
		{
			url = rootUrl + "/advicevaluation/sendtempadvicevaluation";
			data1.lVAF01 = vaf01;
			data1.acf01 = "1";
			data1.lVAF01A = vaf01a;
		}
		else if (bda01 == "3" || bda01 == "8")// 1036
		{
			url = rootUrl + "/advicevaluation/sendedAdviceCaoyaoValuation";
			data1.lVAFID = vaf01;
		}
		else if (bda01 == "S")// 1037
		{
			url = rootUrl + "/advicevaluation/sendedadvicevaluation";
			data1.lVAFID = vaf01;
		}
		else
		// 1038
		{
			url = rootUrl + "/advicevaluation/sendotheradvice";
			data1.VAF01 = vaf01;
			data1.acf01 = "1";
		}
	}
	else
	{
		$("#yizhujijiaContent").empty();
	}
	
	$('#yizhujijia_content').resize(function(){
		$("#yizhujijiaContent").setGridWidth($("#yizhujijia_content").width()*1);
	});
	$.post(url,data1,function(json)
			{
				var rows = json.rows;
				vbd_jqgrid(rows);
			});

}

function vbd_jqgrid(data)
{
	$('#jijia_jq_container').resize(function(){
		$("#yizhujijiaContent").setGridWidth($("#jijia_jq_container").width()*1);
	});
	jQuery('#yizhujijiaContent').GridUnload();
	jQuery("#yizhujijiaContent").jqGrid(
			{
			data:data,
			datatype : "local",
			colModel :
			[
			{
			label : "收费项目",                       
			name : 'vaf22'                            
			},                                        
			{                                         
			label : "规格",                           
			name : 'bby06'                            
			},                                        
			{                                         
			label : "单位",
			name : 'bby08',
			align : 'center'
			},
			{
			label : "数量",
			name : 'vaf21',
			align : 'right'
			},
			{
			label : "单价",
			name : 'lprice',
			sortable : true,
			align : 'right'
			},
			{
			label : "金额",
			name : 'lmoney',
			sortable : true,
			align : 'right'
			},
			{
			label : "执行科室",
			name : 'bck03'
			},
			{
			label : "保险类型",
			name : 'aas02',
			align : 'center'
			}
			],
			sortname : 'lmoney',
			viewrecords : true,
			rowNum : pageSize,
			height : 'auto',
			width : '100%',
			autowidth : true,
			forceFit:true,
		    shrinkToFit:true,
			rownumbers : true,
			footerrow:true, 
			sortorder : "desc",
			loadComplete : function(data)
			{
				var rowNum=parseInt($(this).getGridParam("records"),10);  
				 if(rowNum>0){               
        	    	 $("#yizhujijiaContent .ui-jqgrid-sdiv").show();                
        	    	 var sum=$(this).getCol("lmoney",false,"sum").toFixed(2);  
        	    	 $(this).footerData("set",{"projname":"合计","lmoney":sum});                               //将合计值显示出来           
        	    	 $(this).footerData("set",{"projname":"合计","vaf22":"合计"});                               //将合计值显示出来           
   	     }else{                
   	    		 $("#yizhujijiaContent .ui-jqgrid-sdiv").hide(); 
   	    }
			}
			});
}
// 编辑医嘱信息（传编辑的标志参数，根据参数判断赋值）
function editAdivce()
{
	var vaf01s = "";
	var htFlag = true;// 回退成功标志,发送和新开的编辑分离开
	var checkedAdivce = $(".innerHead td input:checked");
	if (checkedAdivce.length < 1)
	{
		layer.msg("请选择要编辑的医嘱！",
		{
		time : 2000,
		icon : 0,
		skin: 'layui-layer-msg0'
		});
	}
	else if (checkedAdivce.length > 1)
	{
		layer.msg("只能选择一个医嘱单信息进行编辑！",
		{
		time : 2000,
		icon : 0,
		skin: 'layui-layer-msg0'
		});
	}
	else if (checkedAdivce.length == 1)
	{
		var dataStr = [];
		var dataHtmlArr = $(checkedAdivce).parents("tbody").find(".yizhu_details");
		for(var i = 0;i < dataHtmlArr.length;i++)
		{
			dataStr.push(JSON.parse(((dataHtmlArr.eq(i)).attr("data-info"))));
		}
		var dataObj = dataStr[0];
		var vaf10 = dataObj.vaf10;
		cbm01 = dataObj.cbm01;
		if (vaf10 == '1')
		{
			for (var i = 0; i < dataStr.length; i++)
			{
				// var cbm01=dataObj.cbm01;
				dataStr[i] = $.extend(dataStr[i],{'type' : "yizhu_edit"});
			}
			$(window.parent.document).find("#dataStr").val(JSON.stringify(dataStr));
			parent.setEditPara();
//			parent.setEditPara(JSON.stringify(dataStr));
			parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭弹出层

		}
		else if (vaf10 == '8')
		{
			$(checkedAdivce).parents("tbody").find(".yizhu_details").each(function(i, e)
			{
				var dataStr = $(e).attr("data-info");
				var dataObj = JSON.parse(dataStr);
				var vaf01 = dataObj.vaf01;
				$("#cbm01").val(cbm01);
				cbm01 = dataObj.cbm01;
				vaf01s += vaf01 + ",";
				$.ajax(
				{
				url : rootUrl + "/clideladvice/backAdvice",
				type : "post",
				async : false,
				data :
				{
				"cbm01" : cbm01,
				"bce03" : bce03,
				"lbce01" : bce01,
				"lmember" : 2
				},
				dataType : 'json',
				async : false,
				success : function(data)
				{
					if (data.result != "Success")
					{
						layer.msg(data.resultMsg,
						{
						time : 2000,
						icon : 2,
						skin: 'layui-layer-msg2'
						});
						htFlag = false;
					}
				}
				});
			})
			if (htFlag)
			{
				for (var i = 0; i < dataStr.length; i++)
				{
					dataStr[i] = $.extend(dataStr[i],
					{
						'type' : "yizhu_edit"
					});
				}
				$(window.parent.document).find("#dataStr").val(JSON.stringify(dataStr));
				parent.setEditPara();
//				parent.setEditPara(JSON.stringify(dataStr));
				parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭弹出层
			}
		}
		else
		{
			layer.msg('非新开状态的医嘱不允许编辑',
			{
			time : 3000,
			icon : 2,
			skin: 'layui-layer-msg2'
			});
		}
	}
}

// 医嘱checkbox选中事件
// function checkboxEvent(vaf01){
// $(".innerHead td input").on("click",function(){
// if($(this).checked){
// var url = rootUrl + "/sendadvicehistory/herbandoperationsendhistory";;
// var params= {};
// async: false,
// params.lVAFID = vaf01;
// $.post(url,params,function(data){
// var list = data.list;
// $(this).val(list.fvbi15)
//    	    	
// });
// }
// })
// }

// 医嘱操作-----删除
function deleteAdivce()
{
	var vaf01s = "";
	var flag = false;
	var htFlag = true;// 回退成功标志
	// $("#delete_advice_btn").on("click",function(){
	var arr = $(".innerHead td input:checked");
	if (arr.length)
	{
		layer.confirm('确定要删除所选项', 
		{
			btn : [
			'确定', '取消'
			],
			icon:3,
		// 按钮
		}, function()
		{
			$(".innerHead td input:checked").each(function()
			{ // 遍历选中的checkbox
				$(this).parents("tbody").find(".yizhu_details").each(function(i, e)
				{
					var dataStr = $(e).attr("data-info");
					var dataObj = JSON.parse(dataStr);
					var vaf01 = dataObj.vaf01;
					cbm01 = dataObj.cbm01;
					if (dataObj.vaf10 == "1")
					{
						vaf01s += vaf01 + ",";
						flag = true;
					}
					else if (dataObj.vaf10 == "8")
					{
						flag = true;
						vaf01s += vaf01 + ",";
						$.ajax(
						{
						url : rootUrl + "/clideladvice/backAdvice",
						type : "post",
						data :
						{
						"cbm01" : cbm01,
						"bce03" : bce03,
						"lbce01" : bce01,
						"lmember" : 2
						},
						dataType : 'json',
						async : false,
						success : function(data)
						{
							if (data.result != "Success")
							{
								layer.msg(data.resultMsg,
								{
								time : 3000,
								icon : 1,
								skin: 'layui-layer-msg1'
								});
								htFlag = false;
							}
						}
						});
					}

				})
			});
			if (flag && htFlag)
			{
				vaf01s = vaf01s.substring(0, vaf01s.length - 1);
				var url = rootUrl + "/clideladvice/removeAdvice";
				var data =
				{
				"vaf01s" : vaf01s,
				"bce03" : bce03
				};
				var callback = function(data, status)
				{
					if (data.result == "Success")
					{
						layer.msg('删除成功',
						{
						time : 2000,
						icon : 1,
						skin: 'layui-layer-msg1'
						});
						patientDoctorAdvice(vac01, curr);
					}
					else
					{
						layer.msg('数据异常请联系管理员！',
						{
						time : 2000,
						icon : 2,
						skin: 'layui-layer-msg2'
						});
					}
				};
				$.post(url, data, callback);
			}

			else
			{
				layer.msg('包含已结账或者不允许删除的医嘱，请检查',
				{
				time : 2000,
				icon : 0,
				skin: 'layui-layer-msg0'
				});
			}

		}, function()
		{
		});
	}
	else
	{
		layer.msg('请选择要删除的处方',
		{
		time : 2000,
		icon : 0,
		skin: 'layui-layer-msg0'
		});
	}
	// })
}

// 医嘱退费--作废
function vby1()
{
	var xml = new Array();
	var vaf01s = "";
	var cbm01;
	var vaf10;
	var cbm01list;
	var flag = false;
	var count = 0;
	$(".innerHead td input:checked").each(function()
	{ // 遍历选中的checkbox
		count++;
		cbm01list = $(this).parents("tr").attr("data-cbm01List");
		$(this).parents("tbody").find(".yizhu_details").each(function(i, e)
		{
			var dataStr = $(e).attr("data-info");
			var dataObj = JSON.parse(dataStr);
			var vaf01 = dataObj.vaf01;
			cbm01 = dataObj.cbm01;
			vaf10 = dataObj.vaf10;
			if(vaf10!='8')
			{
				flag = true;
			}
			vaf01s += vaf01 + ",";
		})

	});
	if(flag)
	{
		layer.alert("存在不能作废的医嘱，请重新选择！",{icon:0,title:'提示'});
		return;
	}
	else if (count==0)
	{
		layer.msg("请选择要作废的医嘱单",
		{
		time : 2000,
		icon : 0,
		skin: 'layui-layer-msg0'
		});
		return;
	}
	else if (vaf10 == '8')
	{
		vaf01s = vaf01s.substring(0, vaf01s.length - 1);
		layer.confirm("确定作废所选项？", 
		{
			btn : ['确定', '取消'],
			icon:3,
		// 按钮
		}, function()
		{
			layer.msg('作废中....', {icon: 16,skin: 'layui-layer-msg16',shade: [0.1, '#393D49'],time:0}); 
			var url = rootUrl + "/clideladvice/vby1";
			var data =
			{
			"xml" : xml,
			"vaf01s" : vaf01s,
			"bce03" : bce03,
			"lbce01" : bce01,
			"lmember" : 2
			};
			$.ajax({
				url : url,
				type : "post",
				data : data,
				async : false,
				dataType : 'json',
				success : function(data)
				{
					layer.msg(data.resultMsg,
						{
						time : 2000,
						icon : 0,
						skin: 'layui-layer-msg0'
						});
						patientDoctorAdvice(vac01, curr);
					
				}
		});
			
			

		}, function()
		{

		});
	}
}

// 弹出首页界面
function shouye()
{
	if (typeof (vaa01) != "undefined" && vaa01 != "")
	{
		jibenxinxi();
		guomin();
		shouye12();
		shouye13();
		$("#shouye").modal("show");
	}
	else
	{
		layer.msg("请选择病人信息！",{time:2000,icon:0,skin: 'layui-layer-msg0'});
	}
}

// //医嘱回退
function backAdvice()
{
	var cbm01;
	var vaf10;
	$('input:checkbox[name=advice]:checked').each(function(i)
	{
		cbm01 = $(this).parent().parent().children().find("input[name='cbm01']").val();
		vaf10 = $(this).parent().parent().children().find("input[name='vaf10']").val();
	});
	if (typeof (cbm01) == undefined)
	{
		layer.msg("请选择要回退的医嘱单！",{time:2000,icon:0,skin: 'layui-layer-msg0'});
		return;
	}
	else if (vaf10 == "1")
	{
		layer.msg("没有需要回退的医嘱单！",{time:2000,icon:0,skin: 'layui-layer-msg0'});
		return;
	}
	else
	{
		alert("cbm01=" + cbm01 + " 确定回退？");
		var url = rootUrl + "/cloud/clideladvice/backAdvice";
		var data =
		{
		"cbm01" : cbm01,
		"bce03" : bce03,
		"lbce01" : bce01,
		"lmember" : 2
		};
		var callback = function(data, status)
		{
			alert(data.resultMsg);
		};
		$.post(url, data, callback);
	}
}

function print_content()
{
	var datastr = $("#advice_print option:selected").attr("data-info");
	if(datastr){
		var dataObj = JSON.parse(datastr);
		var id = dataObj.id;
		var vaf10 = dataObj.vaf10;
		if(vaf10 == '8'){
			var url = printUrl+"/printtoolrest/printToPdf/"+id+"?cbm01="+cbm01;
	    	layer.closeAll();         // 打印前先关闭已经打开 layer 弹框
	        layer.open({
	            type: 2,
	            title:false,          // title 不显示
	            closeBtn: 0,          // 不显示  layer 弹框关闭按钮
	            shadeClose: false,
	            shade: false,
	            area: ['0%', '0%'],   //在页面上不显示
	            content: url,         //iframe的url,
	            success:function(){
	                // $("#cover").addClass("hidden");  //去掉遮罩层
	                console.log($("#icon"));
	            }
	        });
		}else{
			if(vaf10 == '1'){
				layer.alert("请先发送医嘱单！");
			}else if(vaf10 == '4'){
				layer.alert("医嘱已作废，请重开！");
			}
		}
	}else{
		layer.msg("请选择打印的医嘱单！",{time:2000,icon:0,skin: 'layui-layer-msg0'});
	}
}
